<template>
  <div>
    <div class="icon-btn">
      <!-- 返回首页 -->
      <div class="icon-btn-item" @click="linkTo(detailAll.index_link)">
        <em class="fixed-shop"></em>
        <div>首页</div>
      </div>

      <!-- 分享 -->
      <div class="icon-btn-item" @click="showSharePoster">
        <em class="fixed-share"></em>
        <div>分享</div>
      </div>

      <!-- 联系老师 -->
      <div class="icon-btn-item" @click="contactTeacher">
        <em class="contact_teacher"></em>
        <div>联系老师</div>
      </div>
    </div>
    <goods-code :visible.sync="codeDialogVisible" :codeData="detailAll.qrcode"></goods-code>
    <!-- ST 自定义分享 -->
    <god-share-cpt ref="god-share-cpt" @share="shareGoods"></god-share-cpt>
    <!-- ED 自定义分享 -->
    <!-- 联系老师 -->
    <van-popup
      v-model="dialogVisible"
      class="code-pop"
    >
    <div class="teacher-code-wrap">
      <div class="teacher-code-wrap-close" v-if="dialogVisible"  @click.stop="dialogVisible = false">
        <img src="https://img.wifenxiao.com/h5-wfx/images/DZ/zhile/close.png" alt="">
      </div>
      <div class="teacher-code-img">
        <img :src="detailAll.wild_fire_contract_tea_pic" :show-menu-by-longpress="true" @load="loadImg" alt="">
      </div>
      <div class="tips">长按识别二维码加老师微信哦~</div>
    </div>
    </van-popup>
  </div>
</template>

<script>
  import goodsCode from '../../../../components/goodsCode'
  import GodShareCpt from '@/components/god/god-share'
  import { openPage } from '@/utils/utils.js'
  import { wxItemQrCode } from '@/api/small/common'
  export default {
    components: {
      goodsCode,
      GodShareCpt
    },
    props: {
      detailAll: {
        type: Object,
        default: {}
      }
    },
    data() {
      return {
        codeDialogVisible: false,
        dialogVisible: false,
        imgLoaded: false
      }
    },
    methods: {
      JumpName(url, data) {
        // 定制 3861 设置外链 点击购物车跳转至外链
        if (this.detailAll.is_3861_muyin_dz && this.detailAll.item_detail.buy_method == 2 && url == 'shop-car') {
          window.location.href = this.detailAll.item_detail.buy_url
        } else {
          this.$JumpName(this, url, data)
        }
      },
      Jump(url, data) {
        this.$JumpPath(this, url, data)
      },
      linkTo(url) {
        openPage(url, 1)
      },
      // 分享
      showSharePoster() {
        this.$refs['god-share-cpt'].show(this.detailAll)
      },
      shareGoods() {
        this.$loadingWrap.show()
        wxItemQrCode({item_id: this.detailAll.item_detail.item_id, activity: this.detailAll.activity,activityGroupId: this.$route.query.groupId}).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.detailAll.qrcode = res.data.path
            this.codeDialogVisible = true;
          } else {
            this.$Error(res.msg)
          }
        })
      },
      // 联系老师
      contactTeacher() {
        if (!this.detailAll.wild_fire_contract_tea_pic) {
          this.$Error('该课程暂未关联老师，请联系管理员')
          return false
        }
        this.dialogVisible = true
        if (!this.imgLoaded) {
          this.$loadingWrap.show()
        }
      },
      loadImg() {
        this.$loadingWrap.close()
        this.imgLoaded = true
      }
    }
  }
</script>

<style lang="scss">
  .icon-btn{
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    margin-right:20px;
    &-item{
      display:flex;
      flex-direction: column;
      justify-content: center;
      align-items:center;
      min-width: 90px;
      text-align: center;
      // margin-left: -8px;
      margin-right: 8px;
      font-size:20px;
      color:#333;
      em{
        width: 36px;
        height: 36px;
        display: inline-block;
        // margin-top: 4px;
        &.fixed-shop{
          background: url(https://img.wifenxiao.com/h5-wfx/images/item/detail/shop.png) center no-repeat;
          background-size: 100% auto;
        }
        &.fixed-share{
          background: url(https://img.wifenxiao.com/h5-wfx/images/item/detail/code2.png) center no-repeat;
          background-size: 100% auto;
        }
        &.fixed-collect{
          background: url(https://img.wifenxiao.com/h5-wfx/images/item/detail/collect1_1.png) center no-repeat;
          background-size: 100% auto;          
          &.collected{
            background-image:url("https://img.wifenxiao.com/h5-wfx/images/item/detail/collect2.png");
          }
        }
        &.fixed-share{
          background:url("https://wifenxiao.oss-cn-hangzhou.aliyuncs.com/h5-wfx/images/DZ/xahs/share.png") no-repeat;
          background-size: 100% auto;          
        }
        &.fixed-car{
          background: url(https://img.wifenxiao.com/h5-wfx/images/item/detail/cart2.png) center no-repeat;
          background-size: 100% auto;
        }
        &.fixed-point{
          background: url(https://img.wifenxiao.com/h5-wfx/images/user/point/icon_cart.png) center no-repeat;
          background-size: contain;
        }
        &.contact_teacher {
          width: 40px;
          background: url(https://img.wifenxiao.com/h5-wfx/images/DZ/yhjy/contact-teacher.png) center no-repeat;
          background-size: 100% auto;
        }
      }
      >div{
        margin-top:6px;
      }
      &.cart-item{
        position:relative;
        .num{
          position:absolute;
          min-width:28px;
          height: 28px;
          padding:0 8px;
          top: -2px;
          right: 6px;
          line-height: 28px;
          background: #F30C23;
          font-size:20px;
          color: #fff;
          border-radius: 14px;
          font-weight: normal;
          text-align: center;
        }
      }
    }
  }
  .code-pop {
    background-color: transparent;
    .teacher-code-wrap {
      background: transparent;
      position: relative;
      padding: 50px;
      .teacher-code-wrap-close {
        position: absolute;
        right: 0;
        top: 0;
        width: 60px;
        img {
          width: 100%;
        }
      }
      .teacher-code-img {
        width: 400px;
        background: #fff;
        padding: 10px;
        margin: auto;
        img{
          max-width: 100%;
          width: 100%;
        }
      }
      .tips {
        background: #EF6666;
        padding: 30px 60px;
        color: #fff;
        margin-top: 40px;
        border-radius: 50px;
        white-space: nowrap;
      }
    }
  }
</style>
